<!DOCTYPE html>
<meta charset="utf-8"/>
<meta name="variant" content="">
<meta name="variant" content="?legacy-samesite">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/cookies/resources/cookie-helper.sub.js"></script>
<script>
  function create_test(origin, target, expectedStatus, title) {
    promise_test(t => {
      var value = "" + Math.random();
      return resetSameSiteCookies(origin, value)
        .then(_ => {
          return new Promise((resolve, reject) => {
            var w = window.open(origin + "/cookies/resources/postToParent.py");

            var reloaded = false;
            var msgHandler = e => {
              try {
                getSameSiteVerifier()(expectedStatus, value, e.data, DomSameSiteStatus.SAME_SITE);
              } catch (e) {
                reject(e);
              }

              if (reloaded) {
                window.removeEventListener("message", msgHandler);
                w.close();
                resolve("Popup received the cookie.");
              } else {
                reloaded = true;
                w.postMessage("reload", "*");
              }
            };
            window.addEventListener("message", msgHandler);

            if (!w)
              reject("Popup could not be opened (did you allow the test site in your popup blocker?).");
          });
        });
    }, title);
  }

  create_test(SECURE_ORIGIN, SECURE_ORIGIN, SameSiteStatus.STRICT, "Reloaded same-host auxiliary navigations are strictly same-site.");
  create_test(SECURE_SUBDOMAIN_ORIGIN, SECURE_SUBDOMAIN_ORIGIN, SameSiteStatus.STRICT, "Reloaded subdomain auxiliary navigations are strictly same-site.");
  create_test(SECURE_CROSS_SITE_ORIGIN, SECURE_CROSS_SITE_ORIGIN, SameSiteStatus.LAX, "Reloaded cross-site auxiliary navigations are laxly same-site");
</script>
